const express = require('express');
const path = require('path');
var session = require('express-session');

const app = express();

//设置全局的模板引擎
app.engine('html', require('express-art-template'));

app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: true
  }))
   
//先引入账户路由模块
const accountRouter = require(path.join(__dirname,'./router/accountRouter.js'));
app.use('/account',accountRouter);
//导入静态资源
app.use(express.static(path.join(__dirname,'static')));

//设置权限访问
app.all('/*',(req,res,next)=>{
    if(req.url.includes("account")){
        next()
    }else{
        if (req.session.loginName) {
            next();
        }else{
            res.send("<script>alert('你还没有登录,请重新登录');location.href='/account/login'</script>")
        }
    }
})


//导入学生管理路由模块
const studentManagerRouter = require(path.join(__dirname,'./router/studentManagerRouter.js'));
app.use('/studentManager',studentManagerRouter);

app.listen(3000,(err)=>{
    console.log('启动成功');
})